package com.heima.user.service.ipml;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dtos.AuthDto;
import com.heima.model.user.pojos.ApUserRealname;
import com.heima.user.mapper.ApAuthMapper;
import com.heima.user.service.ApAuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author lzq
 * @data 2023/5/9 19:21
 */
@Service
@Slf4j
public class ApAuthServiceImpl extends ServiceImpl<ApAuthMapper, ApUserRealname> implements ApAuthService {

    /**
     * 用户列表
     * @param dto
     * @return
     */
    @Override
    public ResponseResult list(AuthDto dto) {
        //参数校验
        dto.checkParam();
        if (dto==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //分页
        Page<ApUserRealname> page = new Page<>(dto.getPage(), dto.getSize());
        //条件
        LambdaQueryWrapper<ApUserRealname> lqw = new LambdaQueryWrapper<>();
        lqw.eq(dto.getStatus()!=null,ApUserRealname::getStatus,dto.getStatus());
        page(page,lqw);
        //封装对象
       ResponseResult responseResult = new PageResponseResult(dto.getPage(), dto.getSize(), (int)page.getTotal());
       responseResult.setData(page.getRecords());
        return responseResult;
    }
}
